package app.kotlin_1.utils

import android.support.v4.view.ViewPager
import android.view.View

/**
 * Created by 刘智强 on 2017/9/21.
 * viewpager切换时的动画
 */
class ScrollOffsetTransformer : ViewPager.PageTransformer {

    private val MIN_SCALE: Float = 0.85F
    private  var ex:Float=0f

    constructor(ex: Float) {
        this.ex = ex
    }


    override fun transformPage(page: View?,  position: Float) {
//        position += ex
        var scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position))
        var rotate = 30 * Math.abs(position)
        var transla = 50 * Math.abs(position)
        if (position < -1) {

        } else if (position < 0) {
            page?.setScaleX(scaleFactor);
            page?.setScaleY(scaleFactor);
            page?.setRotationY(rotate);
        } else if (position >= 0 && position < 1) {
            page?.setScaleX(scaleFactor);
            page?.setScaleY(scaleFactor);
            page?.setRotationY(-rotate);
        } else if (position >= 1) {
            page?.setScaleX(scaleFactor);
            page?.setScaleY(scaleFactor);
            page?.setRotationY(-rotate);
        }
    }

}


